package com.bi.autotest.operations;

import com.auto.base.OperateAppium;
import com.bi.autotest.pages.MyLoginPage;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

import java.util.List;

/**
 * Created by yidian on 2018/3/27.
 */
public class MyLoginOperation extends OperateAppium {

    private MyLoginPage myLoginPage;

    public MyLoginOperation(AndroidDriver androidDriver) {
        super(androidDriver);

        myLoginPage=new MyLoginPage(androidDriver);
    }


    /**
     * 进入登录页面的操作
     * @return
     */
    public boolean LoginPre(){
        exePre();
        boolean isLoginPage=myLoginPage.isLoginPage();
        return isLoginPage;
    }


    public void clearText(){
        //先去清空输入框的内容
        clearText(myLoginPage.getNameInputArea());
        clearText(myLoginPage.getPassWordInputArea());
    }
    public boolean login(String name,String pass){
        input(myLoginPage.getNameInputArea(),name);
        input(myLoginPage.getPassWordInputArea(),pass);
        clickView(myLoginPage.getLoginButton());
        sleep(3000);
        boolean isSucess=myLoginPage.isLoginSuccess();
        return isSucess;
    }

    public void exePre(){
       sleep(5000);
      //  AndroidElement ae= (AndroidElement) driver.findElementByXPath("//android.widget.TextView[@text='我']");
        AndroidElement ae= (AndroidElement) driver.findElementByName("我");
        if(ae==null){
            List<AndroidElement> list=driver.findElementsById("com.tencent.mm:id/ca3");
            ae= list.get(3);
        }

        ae.click();
       sleep(3000);
        driver.findElementByName("收藏").click();
       sleep(3000);
       // driver.findElementByXPath("//android.widget.TextView[@text='https://msdev.188yd.com/wxh/seller/qrcodeByStore']").click();
        driver.findElementById("com.tencent.mm:id/b53").click();
        sleep(3000);
        driver.findElementById("com.tencent.mm:id/b6x").click();
       sleep(10000);

    }


    public boolean LoginPreNew(){
        exePre();
        boolean isSuccessPage=myLoginPage.isCacheLoginSuccessPage();
        return isSuccessPage;
    }

    public void exePreNew(){
        sleep(5000);
        AndroidElement ae= (AndroidElement) driver.findElementByName("女亭");
        ae.click();
        sleep(2000);
        AndroidElement ae1= (AndroidElement) driver.findElementById("com.tencent.mm:id/apz");
        ae1.click();
    }

    public void selectGG(){
        myLoginPage.getGGButton().click();
        myLoginPage.getConfirmLoginButton().click();
        sleep(2000);
    }


}
